﻿using System;
using System.Collections.Generic;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Reflection;
using System.Web;

namespace WmsService.Util
{
    public class EntityChanger
    {
        public static TBaseEntity ChangeEntityToBase<TEntity, TBaseEntity>(TEntity entity) 
            where TBaseEntity:EntityObject ,new()
            where TEntity : TBaseEntity
        {
            var baseEntity = new TBaseEntity();
            PropertyInfo[] propertyInfos = typeof (TBaseEntity).GetProperties();
            foreach (var propertyInfo in propertyInfos)
            {
                if(propertyInfo.Name != "EntityKey" && propertyInfo.CanRead && propertyInfo.CanWrite)
                {
                    propertyInfo.SetValue(baseEntity,propertyInfo.GetValue(entity,null),null);
                }
            }
            return baseEntity;
        }
    }
}